//index.js
//获取应用实例
const app = getApp();
const api = require('../../utils/api.js');
Page({
  data: {
    loading: false,
    inputValue: '',
    error: 0,
    index: 0,
    area: [{ id: 4, name: '亚太' }, { id: 1, name: '北美' }, { id: 2, name: '欧洲' }, { id: 3, name: '南美' }, { id: 5, name: '澳大利亚' }],
  },
  bindArea: function(e) {
    this.setData({
      index: e.detail.value
    })
  },
  restInput: function(e) {
    this.setData({
      error: 0,
      inputValue: e.detail.value
    })
  },
  //搜索steam用户昵称
  searchName: function() {
    // 获取输入框中的用户昵称
    let inputValue = this.data.inputValue;
    let reg = /[0-9a-zA-Z_]{3,}/
    let region = this.data.area[this.data.index].id

    if (reg.test(inputValue)) {
      wx.redirectTo({ url: '../list/list?act=bind&name=' + inputValue + '&region=' + region })
    } else {
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '输入的昵称只能为英文下划线数字，长度大于三。',
      })
    }
  },
  // 分享
  onShareAppMessage: function() {
    return {
      title: 'h1z1群排行',
      path: 'pages/index/index'
    }
  }
})